import QtQuick 2.0

Rectangle {
    id: root

    default property string azString: "↑＊ABCDEFGHIJKLMNOPQRSTUVWXYZ#↓"
    signal clickIndexSignal(var indexString)
    signal releasedSignal

    property int currentIndex: 0

    color: "transparent"


    Column {
        anchors.fill: parent
        Repeater {
            model: azString.length
            delegate: Item {
                width: parent.width
                height: root.height / azString.length
                AText {
                    color: m_mouseArea_id.pressed ? "#000000" : "lightgrey"
                    anchors.centerIn: parent;
                    text: azString[index]
                    font.pixelSize: parent.height*0.8
                }
            }
        }
    }

    function clickIndexSlot(index) {
        if (currentIndex !== index) {
            currentIndex = index
            clickIndexSignal(azString[index])
        }
    }

    function getIndex(mouseY) {
        var result = Math.round(mouseY / (root.height / azString.length));
        if (result >= azString.length) {
            result = (azString.length - 1)
        }

        if (result < 0) {
            result = 0
        }

        return result
    }

    MouseArea {
        id: m_mouseArea_id
        anchors.fill: parent
        onPositionChanged: clickIndexSlot(getIndex(mouseY))

        onPressed: clickIndexSlot(getIndex(mouseY))

        onReleased: releasedSignal()
    }
}

